#include "libutilsconfig.h"
#include "maths.h"
#include <cstdlib>
#include <cmath>

int32 LIB_NS::UMaths::Abs( int32 value )
{
	return std::abs(value);
}

float LIB_NS::UMaths::Abs( float value )
{
	return (float)std::fabs(value);
}

double LIB_NS::UMaths::Abs( double value )
{
	return std::fabs(value);
}

int32  LIB_NS::UMaths::Ceiling( double value )
{
	return (int32 )(value+0.9999999999);
}
int32  LIB_NS::UMaths::Floor( double value )
{
	return (int32 )value;
}

double LIB_NS::UMaths::Log( double value )
{
	return std::log(value);
}

double LIB_NS::UMaths::Log10( double value )
{
	return std::log10(value);
}

double LIB_NS::UMaths::Sqrt( double value )
{
	return std::sqrt(value);
}

double LIB_NS::UMaths::Exp( double value )
{
	return std::exp(value);
}
int32  LIB_NS::UMaths::Sign( double value )
{
	if (value >0)		
		return 1;		
	else if  (value <0)		
		return -1;		
	else
		return 0;
}

int32  LIB_NS::UMaths::ToInt32( const TCHAR* pValue )
{
	return _tstoi(pValue);
}

double LIB_NS::UMaths::ToDouble( const TCHAR * pvalue )
{
	return _tstof(pvalue);
}

#ifdef INCLUDE_PYTHON

#include <Python.h>
#pragma comment(lib,"python25.lib")

#pragma message("compiled used python")

double LIB_NS::UMaths::CaculateExpression(const TCHAR* Expression)
{

	char szExpression[1024];
	Py_Initialize(); 
	sprintf(szExpression,"from math import *\n"						 
		"ans=%s\n"
		"print ans",Expression);
	PyRun_SimpleString(szExpression);

	PyRun_SimpleString("from time import time,ctime\n" 
		"print 'Today is',ctime(time())\n"); 

	Py_Finalize(); 	

	return 0;	
}



#endif